package com.neuedu.controller;

import com.neuedu.entity.ProductDetail;
import com.neuedu.service.ProductDetailService;
import com.neuedu.vo.ProductDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: MARK
 * @Date: 2019/8/6 10:38
 * @Version: 1.0.0
 * @Description:
 */
@RestController
@Transactional
@RequestMapping(value = "/productDetail")
public class ProductDetailController {
    @Autowired
    private ProductDetailService productDetailService;

    @GetMapping
    public List<ProductDetailVO> getAll(){
        List<ProductDetailVO> list = productDetailService.selectAll();
        return list;
    }

    @GetMapping("{id}")
    public ProductDetailVO getOne(@PathVariable("id") Integer id){
        ProductDetailVO productDetailVO = productDetailService.selectOne(id);
        return productDetailVO;

    }

    @PostMapping
    public String add(@RequestBody ProductDetail productDetail){
        productDetailService.add(productDetail);
        return "ok";
    }

    @DeleteMapping(value = "{id}")
    public String delete(@PathVariable("id") Integer id){
        productDetailService.delete(id);
        return "ok";
    }

    @DeleteMapping
    public String batchDelete(@RequestBody List<Integer> ids){
        productDetailService.batchDelete(ids);
        return "ok";
    }
}
